package cn.tedu.property_management_system.controller;

import cn.tedu.property_management_system.service.IUploadService;
import cn.tedu.property_management_system.utils.Constant;
import cn.tedu.property_management_system.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

@Slf4j
@RestController
@RequestMapping("upload")
public class UploadController implements Constant {

    @Autowired
    IUploadService service;

    @PostMapping("img/complaintImg")
    public String uploadComplaintImg(@RequestBody MultipartFile file){
        log.debug("用户尝试上传投诉图片");
        String fullName=service.uploadImg(file,COMPLAINT_IMG_FILE_PRE);
        return fullName;
    }

    @PostMapping("img/repair")
    public String uploadRepairImg(@RequestBody MultipartFile file){
        String fullName = service.uploadImg(file, REPAIR_IMG_FILE_PRE);
        //返回上传文件名
        return fullName;
    }

    @GetMapping("img/complaintImg/remove")
    public JsonResult removeComplaintImg(String name){
        log.debug("尝试删除图片,图片名为:{}",name);
        service.deleteComplaintImgPic(name);
        return JsonResult.OK();
    }

    @GetMapping("img/repair/remove")
    public JsonResult removeRepairImg(String name){
        log.debug("尝试删除图片,图片名为:{}",name);
        service.deleteRepairImgPic(name);
        return JsonResult.OK();
    }

}
